package cn.lger.config;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.ibatis.io.Resources;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.io.IOException;
import java.util.Properties;

/**
 * Code that Changed the World
 *
 * @author Pro
 * @date 2018-06-14.
 */
@Configuration
public class DaoConfig {

    /*@Bean
    public DataSource dataSource() throws IOException {
        Properties properties = Resources.getResourceAsProperties("classpath:db.properties");
        DataSource dataSource = new ComboPooledDataSource();
        ((ComboPooledDataSource) dataSource).setProperties(properties);
        return dataSource;
    }

    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean() {
        SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
        ClassPathResource resource = new ClassPathResource("classpath:mybatis-config.xml");
        sessionFactoryBean.setDataSource(dataSource);
        sessionFactoryBean.setConfigLocation(resource);
        return sessionFactoryBean;
    }

    @Bean
    public DataSourceTransactionManager transactionManager(){
        DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
        transactionManager.setDataSource(dataSource);
        return transactionManager;
    }*/

}
